package com.g2room.search.es.test;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.elasticsearch.search.sort.SortBuilder;

import com.g2room.search.es.po.BasePo;

/**
 * 搜索條件TO类
 * 
 * @author Administrator
 *
 */
public class SearchParamTo extends BasePo implements Serializable {
	private static final long serialVersionUID = 3986472342572198311L;
	/** 搜索开始位置 */
	private int start = 0;
	/** 搜索每页结果 */
	private int size = 20;
	/** 索引类型 */
	private String type;
	/** 搜索参数集合，key为字段 */
	private Map<String, Object> param;
	/** 排序，多个 */
	private List<SortBuilder> sorts;
	private SortBuilder sort;
	/** 搜索結果排除的值，格式为key_value */
	private List<String> exce;

	public SortBuilder getSort() {
		return sort;
	}

	public void setSort(SortBuilder sort) {
		this.sort = sort;
	}

	public List<String> getExce() {
		return exce;
	}

	public void setExce(List<String> exce) {
		this.exce = exce;
	}
	
	public List<SortBuilder> getSorts() {
		return sorts;
	}

	public void setSorts(List<SortBuilder> sorts) {
		this.sorts = sorts;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Map<String, Object> getParam() {
		return param;
	}

	public void setParam(Map<String, Object> param) {
		this.param = param;
	}

//	public void convert2Map(Object obj) {
//		Map<String, Object> map = new HashMap<String, Object>();
//		try {
//			PropertyUtils.copyProperties(map, obj);
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//		this.setParam(map);
//	}
//	
//	public static Map<String, Object> getparamsToIndex(Object obj) {
//        Field[] declaredFields = obj.getClass().getDeclaredFields();
//        List<String> transientfields = new ArrayList<String>();
//        for(Field field : declaredFields){
//            if(field.isAnnotationPresent(Transient.class)){
//                transientfields.add(field.getName());
//            }
//        }
//         
//        Map<String, Object> params = new HashMap<String, Object>(0);
//        try {
//            PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean();
//            PropertyDescriptor[] descriptors = propertyUtilsBean.getPropertyDescriptors(obj);
//            for (int i = 0; i < descriptors.length; i++) {
//                String name = descriptors[i].getName();
//                if (!StringUtils.equals(name, "class")&&!descriptors[i].getReadMethod().isAnnotationPresent(Transient.class)&&!transientfields.contains(name)) {
//                     
//            params.put(propertyToField(name), propertyUtilsBean.getNestedProperty(obj, name));
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return params;
//    }
}
